﻿using System;
using System.Web.UI;
using DevExpress.Web.ASPxMenu;
using System.Xml;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Common;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;
using SGRapidForm.Permission.Entity;
using System.Collections.Generic;
using DevExpress.Web.ASPxGridView;

namespace SGDemo.Permission
{
    public partial class AddUserRole : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
        }


        /// <summary>
        /// 自定义GridView回调重新绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwList_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            gvwList.PageIndex = 0;
            gvwList.DataBind();
        }

        /// <summary>
        /// 为用户添加角色
        /// </summary>
        /// <param name="userKeyid">用户Keyid</param>
        /// <param name="userName">用户名称</param>
        /// <param name="roleKeyids">角色Keyid集合</param>
        /// <param name="roleCodes">角色代码集合</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool BulkAddUserRole(string userKeyid, string userName, string[] roleKeyids, string[] roleCodes)
        {
            //传入参数构造List<UserRole>
            List<UserRole> userRoles = new List<UserRole>();
            for (int i = 0; i < roleKeyids.Length; i++)
            {
                userRoles.Add(new UserRole(userKeyid, userName, roleKeyids[i], roleCodes[i]));
            }
            return _permissionService.UserRole_BulkAdd(userRoles);
        }
    }

    public class AddUserRoleDataSource
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        public List<Role> GetUnmappedRoleByUserKeyid(string keyid, string filterConditions)
        {
            return _permissionService.UserRole_GetUnmappedRoleByUserKeyid(keyid, filterConditions);
        }
    }
}